define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/index' + location.search,
                    // add_url: 'shop/add',
                    // edit_url: 'shop/edit',
                    // del_url: 'shop/del',
                    multi_url: 'shop/multi',
                    import_url: 'shop/import',
                    table: 'shop',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // 列表:商家名称，商家照片，营业执照，负责人身份证照片，商家位置，联系方式，状态(待审核，通过，驳回【驳回原因】)，入驻申请人昵称，入驻申请人手机号，入驻申请时间，入驻会员等级
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'license', title: __('License'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'id_card', title: __('Id_card'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {0:'待审核',1:'成功',2:'驳回'}, formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'user.username', title: __('入驻申请人昵称'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('入驻申请人手机号'), operate: 'LIKE'},
                        {field: 'createtime', title: __('入驻申请时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'package_name', title: __('入驻会员等级'), operate: false},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'operate', buttons: [{
                                name: '审核',
                                hidden:function(row){
                                    if(row.status != 0){
                                        return true;
                                    }
                                },
                                text: __('审核'),
                                classname: 'btn btn-danger btn-xs btn-detail btn-dialog',
                                url: function(row){
                                    return 'shop/edit/ids/'+row.id;
                                }
                            }], title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
